<?php

	require_once('../src/prelude.php');


	if (! isset($_GET['type'])) {

		displayXHTMLDocument('ClassExplorer &ndash; Error',
					 		'<h1>ClassExplorer Error</h1>' .
					 		'<p>No type for source display given. Set the <em>type</em> attribute in the URL.</p>');
	}
	else {

		$sType = $_GET['type'];
		$sContent = '';

		if (is_built_in($sType)) {

			$sContent = '<p>No source files for built-in classes.</p>';
		}
		else {


			$objReflector = new ReflectionClass($sType);
			$sFileName = $objReflector -> getFileName();

			if (file_exists($sFileName) && is_readable($sFileName)) {

				ob_start();
				highlight_file($sFileName);

#				$arrSource = explode("\r<br />", ob_get_clean());
#				$arrSource = preg_split("~(\r|\n)<br />~", ob_get_clean());
				$arrSource = explode("<br />", ob_get_clean());
				$sSource = '';
				$iLine = '1';
				foreach ($arrSource as $sSourceLine) {

					$sLine = '<span class="lineNumber">'. sprintf('% 5d', $iLine) .'</span>';
					$sSource .= "<a name=\"line-$iLine\" class=\"sourceCodeLine\"></a><br />". $sLine . $sSourceLine ."\n";

					$iLine++;
				}

				$sContent = '<p style="white-space:nowrap;">'. $sSource .'</p>';
			}
			else {

				$sContent = "<p>Source file '$sFileName' not readable.</p>";
			}
		}

		displayXHTMLDocument("Source of $sType", $sContent);
	}

?>